package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaDeviceParamType;
import com.sailfish.springbootdemo.service.db1.PcbaDeviceParamTypeService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin
@RequestMapping("/pcbaDeviceParamType")
public class PcbaDeviceParamTypeController {

    @Autowired
    private PcbaDeviceParamTypeService pcbaDeviceParamTypeService;

    @PostMapping("/getPcbaDeviceParamTypeByPcbaDeviceTypeId")
    public Result getPcbaDeviceParamTypeByPcbaDeviceTypeId(HttpServletRequest request, Integer pcbaDeviceTypeId, String searchValue) {
        try {
            return ResultUtil.success(pcbaDeviceParamTypeService.getPcbaDeviceParamTypeByPcbaDeviceTypeId(request, pcbaDeviceTypeId, searchValue));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/deletePcbaDeviceParamType")
    public Result deletePcbaDeviceParamType(Integer pcbaDeviceParamTypeId) {
        return pcbaDeviceParamTypeService.deletePcbaDeviceParamType(pcbaDeviceParamTypeId);
    }

    @PostMapping("/addOrUpdatePcbaDeviceParamType")
    public Result addOrUpdatePcbaDeviceParamType(String mode, PcbaDeviceParamType pcbaDeviceParamType) {
        return pcbaDeviceParamTypeService.addOrUpdatePcbaDeviceParamType(mode, pcbaDeviceParamType);
    }
}
